﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.SessionState;
using MvcIoc.Controllers;
using MvcIoc.Service;

namespace MvcIoc.Infrastructure
{
    public class CustomControllerFactory : IControllerFactory
    {
        public IController CreateController(System.Web.Routing.RequestContext requestContext, string controllerName)
        {
        //    if (controllerName.ToLower().StartsWith("proteintracker"))
        //    {
        //        var service = new ProteinTrackerService();
        //        var controller = new ProteinTrackerController(service);
        //        return controller;
        //    }
            var defultFactory = new DefaultControllerFactory();
            return defultFactory.CreateController(requestContext, controllerName);
        }

        public System.Web.SessionState.SessionStateBehavior GetControllerSessionBehavior(System.Web.Routing.RequestContext requestContext, string controllerName)
        {
            return SessionStateBehavior.Default;
        }

        public void ReleaseController(IController controller)
        {
            var disposable = controller as IDisposable;
            if (disposable != null)
            {
                disposable.Dispose();
            }
        }
    }
}